package top.riske.animalhazardassessment.knowledge;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.riske.animalhazardassessment.common.entity.Article;
import top.riske.animalhazardassessment.common.mapper.ArticleMapper;

import java.util.List;

@Tag(name = "ArticleController",description = "文章管理")
@Slf4j
@RestController
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @Resource
    private ArticleMapper articleMapper;

    @Operation(summary = "获取全部文章")
    @GetMapping("/article/getAll")
    public List<Article> getAll(){
        return articleMapper.selectList(null);
    }

    @Operation(summary = "根据id获取文章")
    @GetMapping("/article/getById")
    public Article getById(@RequestParam Long id){
        return articleMapper.selectById(id);
    }

    @Operation(summary = "根据id删除文章")
    @GetMapping("/admin/article/deleteById")
    public boolean deleteById(@RequestParam Long id){
        return articleMapper.deleteById(id) > 0;
    }

    @Operation(summary = "添加文章")
    @PostMapping("/admin/article/addArticle")
    public void addArticle(@Parameter(description = "只需要title和content就可以了") @RequestBody Article article){
        article.setAccountId(1L);
        articleMapper.insert(article);
    }

}
 